<template>
  <view class="page flex-col" style="{ height: screenHeight }">
    <view class="group_5 flex-col">
      <text class="text_1">您好,欢迎进入</text><br/>
      <text class="text_2">采气工艺移动端监测平台</text>
      <view class="group_6 flex-row justify-between">
        <image
          class="thumbnail_1"
          referrerpolicy="no-referrer"
          src="../img/Slice.png"
        />
		<input class="text_3" v-model="loginForm.username" focus placeholder="请输入账号"/> 
      </view>
      <view class="group_2 flex-col"></view>
      <view class="group_7 flex-row justify-between">
        <image
          class="thumbnail_2"
          referrerpolicy="no-referrer"
          src="../img/qq2x.png"
        />
		<input class="text_4" v-model="loginForm.password" hold-keyboard placeholder="请输入密码" password=true >
      </view>
      <view class="group_4 flex-col "></view>
      <view class="group_8 ">
        <image
          class="thumbnail_3"
          referrerpolicy="no-referrer"
          src="../img/icon-验证码.svg"
        />
        <input class="text_6" v-model="loginForm.code" placeholder="请输入验证码"/> 
        <view class="group_011"><image class="www2"  :src="codeUrl" @click="getCode"  /></view>
		<view class="group_44 flex-col "></view>      
	  </view>
      <view class="group_10 flex-col"></view>
      <button type='default' class="text-wrapper_1 flex-col" @click="onClick_1()" >
        <text class="text_5">登录</text>
      </button>
    </view>
	<image
	  class="image_1 "
	  referrerpolicy="no-referrer"
	  src="../img/qqq2x.png"
	/>
  </view>
</template>
<script>
import request from '../../common/request/request.js'
export default {
  data() {
    return {
		screenHeight: 0,
		statusCode2:0,
		cookiePass: '',
      loginForm: {
              username: '',
              password: '',
              rememberMe: false,
              code: '',
              uuid: ''
        },
		codeUrl: '',
		headerUrl:{
			intranet:'http:/'+'/'+'10.89.67.239:',
			local:'http:/'+'/'+'10.89.67.239:',
		},
		loading: false,
    };
  },
  onLoad() {
	  //获取高度
	  this.screenHeight = uni.getSystemInfoSync().windowHeight
  	// 获取验证码
  	    this.getCode()
  	    // // 获取用户名密码等Cookie
  	    //this.getCookie()
  	    // // token 过期提示
  	    //this.point()
  	
  },
  methods: {
	  //获取验证码
	  getCode() {
		  //console.log("进入没");
	  	let url = this.$requestUrl.requestUrl('/yz')+'/auth/code'
		//let url = 'http://10.89.67.239:8899/yz/auth/code'
	  	uni.request({
	  		url: url,
	  		header: {
	  		   'content-type': 'application/json;charset:utf-8'
	  		},
			data:{
				
	  		},
	  		method: 'GET',
	  		success: res => {
				//console.log(res);
	  			let data = res.data
	  			this.codeUrl = data.img
	  			this.loginForm.uuid = data.uuid
	  		},
			fail:(err) =>{
				console.log("失败");
				console.log(err);
				},
	  	});
	  	
	  },
	  //获取cookie
	 /* getCookie() {
	        const username = Cookies.get('username')
	        let password = Cookies.get('password')
	        const rememberMe = Cookies.get('rememberMe')
	        // 保存cookie里面的加密后的密码
	        this.cookiePass = password === undefined ? '' : password
	        password = password === undefined ? this.loginForm.password : password
	        this.loginForm = {
	          username: username === undefined ? this.loginForm.username : username,
	          password: password,
	          rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
	          code: ''
	        }
	      }, */
		  //token 过期提示
		 /* point() {
		        const point = this.Cookies.get('point') !== undefined
		        if (point) {
		          this.$notify({
		            title: '提示',
		            message: '当前登录状态已过期，请重新登录！',
		            type: 'warning',
		            duration: 5000
		          })
		          Cookies.remove('point')
		        }
		      }, */
    onClick_1() {
		
      //console.log("点击登录了");
	  const authUser = {
	            username: this.loginForm.username,
	            password: this.loginForm.password,
	            code: this.loginForm.code,
	            uuid: this.loginForm.uuid,
				rememberMe: this.loginForm.rememberMe,
	          }
			 let url = this.$requestUrl.requestUrl('/yz')+'/auth/appLogin?username='+authUser.username+'&password='+
			 authUser.password+'&code='+authUser.code+'&uuid='+authUser.uuid;
			 this.statusCode2=0;
			 uni.request({
			 	url: url,
			 	data:{	
			 	},
			 	method: 'POST',
			 	success: res => {
					// 登录失败验证
					if(res.data.status == 400) {
						console.log("进登录失败");
						uni.showToast({
						    title: res.data.message,
							icon:'none'
						});
					}else {
						// 保存 token
						this.statusCode2=res.statusCode;
						uni.setStorageSync('Authorization', res.data.token);
						//账号
						uni.setStorageSync('userMing', res.data.user.user.username);
						//名字
						uni.setStorageSync('userName', res.data.user.user.nickName);
						//单位id
						uni.setStorageSync('unitId', res.data.user.user.orgId);
						//部门id
						uni.setStorageSync('departmentId', res.data.user.user.dept.id);
						//部门名字
						uni.setStorageSync('department', res.data.user.user.dept.name);
						//手机号
						uni.setStorageSync('phone', res.data.user.user.phone);
						/* var account = uni.getStorageSync('userMing');
						var userName = uni.getStorageSync('userName'); */
						/* console.log(userName);
						console.log(account); */
						uni.request({
							url:this.$requestUrl.requestUrl('/yz')+'/api/dept/getCompanyByDeptId?dept_id='+res.data.user.user.dept.id,
							data:{	
							},
							method: 'GET',
							success: rese => {
								//单位
								uni.setStorageSync('company', rese.data.name);	
							},	
						})
						if(this.statusCode2 ==200){
							uni.redirectTo({
							url:'./index',
							success:res =>{
								console.log("成功");
							},
							fail:(err) =>{
								console.log("失败");
								console.log(err);
								},
							complete:() => {},
							})
						}
					}
			 	},		
			 });
    },
	},
};
</script>
<style scoped>
.page {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 1);
  overflow: hidden;
}
.group_5 {
  width: 100%;
  height: 100%;
 margin-top: 100rpx;
}

.text_1 {
  width: 92rpx;
  height: 48rpx;
  display: inline-block;
  overflow-wrap: break-word;
  color: rgba(97, 97, 97, 1);
  font-size: 40rpx;
  font-family: MicrosoftYaHei-Bold;
  white-space: nowrap;
  line-height: 48rpx;
  text-align: left;
  margin-left: 90rpx;
}

.text_2 {
  width: 320rpx;
  height: 48rpx;
  display: inline-block;
  overflow-wrap: break-word;
  color: rgba(97, 97, 97, 1);
  font-size: 40rpx;
  font-family: MicrosoftYaHei-Bold;
  white-space: nowrap;
  line-height: 48rpx;
  text-align: left;
  margin: 12rpx 0 0 90rpx;
}

.group_6 {
  width: 172rpx;
  height: 36rpx;
  margin: 136rpx 0 0 112rpx;
}

.thumbnail_1 {
  width: 32rpx;
  height: 34rpx;
}

.text_3 {
  width: 200rpx;
  height: 36rpx;
  /* display: inline-block; */
  overflow-wrap: break-word;
  color: rgba(208, 208, 208, 1);
  font-size: 24rpx;
  font-family: MicrosoftYaHei;
  white-space: nowrap;
  line-height: 36rpx;
  text-align: left;
  margin-left: 40rpx;
  margin-top: -42rpx;
}

.group_2 {
  width: 542rpx;
  height: 2rpx;
  background: url(https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPngeb4955b649af667305ee00b81e86e681ce252112fb2ca7d36c77685f76df7b02)
    0px 0px no-repeat;
  background-size: 542rpx 4rpx;
  margin: 12rpx 0 0 112rpx;
}

.group_7 {
  width: 172rpx;
  height: 36rpx;
  margin: 54rpx 0 0 112rpx;
}

.thumbnail_2 {
  width: 32rpx;
  height: 32rpx;
}

.text_4 {
  width: 240rpx;
  height: 36rpx;
 /* display: inline-block; */
  overflow-wrap: break-word;
  color: rgba(208, 208, 208, 1);
  font-size: 24rpx;
  font-family: MicrosoftYaHei;
  white-space: nowrap;
  line-height: 32rpx;
  text-align: left;
  margin-left: 40rpx;
  margin-top: -42rpx;
}

.group_4 {
  width: 542rpx;
  height: 2rpx;
  background: url(https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPngeb4955b649af667305ee00b81e86e681ce252112fb2ca7d36c77685f76df7b02)
    0px 0px no-repeat;
  background-size: 542rpx 4rpx;
  margin: 12rpx 0 0 112rpx;
}
.group_44 {
  width: 360rpx;
  height: 2rpx;
  background: url(https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPngeb4955b649af667305ee00b81e86e681ce252112fb2ca7d36c77685f76df7b02)
    0px 0px no-repeat;
  background-size: 542rpx 4rpx;
  margin: 12rpx 0 0 0px;
}
.group_8 {
  width: 532rpx;
  height: 48rpx;
  margin: 54rpx 0 0 112rpx;
}

.thumbnail_3 {
  width: 32rpx;
  height: 32rpx;
}

.text_6 {
  width: 144rpx;
  height: 36rpx;
  display: inline-block;
  overflow-wrap: break-word;
  color: rgba(208, 208, 208, 1);
  font-size: 24rpx;
  font-family: MicrosoftYaHei;
  white-space: nowrap;
  line-height: 36rpx;
  text-align: left;
  margin-left: 10rpx;
}

.group_9 {
  width: 160rpx;
  height: 60rpx;
  margin: -54rpx;
  background-color: rgba(226, 226, 226, 1);
  margin-left: 374rpx;
}
.group_011 {
	 width: 100%;
	    display: inline-block;
	    height: 40rpx;
	    float: right;
	    img{
	      cursor: pointer;
	      vertical-align:middle;}
}
.group_10 {
  width: 376rpx;
  height: 2rpx;
  /* background: url(https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng783e3c034cd952b432a95456fdd16294fb80d5567273907c09aa0bc1f3e9eb90)
    0px 0px no-repeat; */
  background-size: 376rpx 4rpx;
  margin-left: 104rpx;
}

.text-wrapper_1 {
  height: 84rpx;
  border-radius: 42rpx;
  background-color: rgba(240, 155, 0, 1);
  width: 560rpx;
  margin: 94rpx 0 0 104rpx;
}

.text_5 {
  width: 300rpx;
  height: 48rpx;
  display: inline-block;
  overflow-wrap: break-word;
  color: rgba(255, 255, 255, 1);
  font-size: 36rpx;
  font-family: MicrosoftYaHei-Bold;
  white-space: nowrap;
  line-height: 44rpx;
  text-align: left;
  margin: 18rpx 0 0 236rpx;
}

.image_1 {
  width: 100%;
  /* height: 160px; */
 margin-top: 180rpx;
}
.www2{
	width: 120rpx;
	 height: 120rpx;
	margin-left:350rpx;
	margin-top:-95rpx;
}
</style>